import LevelBaseControl from "../LevelCommon/LevelBaseControl";
import RotateObj from "../Prefabs/InteractivObj/Common/RotateObj";
import MoveObj from "../Prefabs/InteractivObj/Common/MoveObj";
import GamePropConst from "../../constant/GamePropConst";
import DialogDataConst from "../../constant/DialogDataConst";
import Sound from "../../constant/SoundNameConstant";

export default class LevelControl8 extends LevelBaseControl{
  
    //#region room1
    /** 柜子门1*/
    private guizi1:RotateObj;
    /** 柜子门1*/
    private guizi2:RotateObj;
    /** 柜子门1*/
    private guizi3:RotateObj;
    /** 柜子门1*/
    private guizi4:RotateObj;
    /** 密码机器下面的门*/
    private machineGate:RotateObj;
    /** 画*/
    private drawObj:RotateObj;
    /** 画是否显示出了四角*/
    private isShowDrawCorner:boolean = false;
    /** 画corner1是否钻孔*/
    private isCornner1Zuan:boolean = false;
    /** 画corner2是否钻孔*/
    private isCornner2Zuan:boolean = false;
    /** 画corner3是否钻孔*/
    private isCornner3Zuan:boolean = false;
    /** 画corner4是否钻孔*/
    private isCornner4Zuan:boolean = false;
    /** 电梯门1*/
    private diantiGate1:MoveObj;
    /** 电梯门2*/
    private diantiGate2:MoveObj;
    /** 电梯是否开了*/
    private isOpenDianTi:boolean = false;
    //#endregion

    protected startByBase(){
        this.InitRoom1();
    }

    private InitRoom1()
    {
        let room1 = this.allLevelObjs[0].owner;
        let wall1 = room1.getChildByName("walls").getChildByName("wall1");
        let wall2 = room1.getChildByName("walls").getChildByName("wall2");
        let wall4 = room1.getChildByName("walls").getChildByName("wall4");

        this.guizi1 =wall2.getChildByName("box_props").getChildByName("box_props").getChildByName("door_props").getComponent(RotateObj);

        this.guizi2 = wall2.getChildByName("box_props001").getChildByName("box_props001").getChildByName("door_props001").getComponent(RotateObj);
        this.guizi3 = wall2.getChildByName("box_props002").getChildByName("box_props002").getChildByName("door_props002").getComponent(RotateObj);
        this.guizi4 = wall2.getChildByName("box_props003").getChildByName("box_props003").getChildByName("door_props003").getComponent(RotateObj);
        
        this.machineGate = wall4.getChildByName("computer").getChildByName("machineGate").getChildByName("switch").getComponent(RotateObj);
        

        this.drawObj = wall1.getChildByName("drawFocus").getChildByName("draw").getComponent(RotateObj);
        
        this.diantiGate1 = wall1.getChildByName("dianti").getChildByName("Box013").getComponent(MoveObj);
        this.diantiGate2 = wall1.getChildByName("dianti").getChildByName("Box014").getComponent(MoveObj);
    }

    public  DoInteractObjLogic( _name:string):boolean
    {
        switch (_name)
        {
            /** 解锁柜子门 打开*/
            case "password BOX0_UnLock":
                this.guizi1.Interactive();
                Laya.timer.once(500,this,this.ShowDialogNothing);
            break;
            /** 解锁柜子门 打开*/
            case "password BOX1_UnLock":
                this.guizi2.Interactive();
                break;
            /** 解锁柜子门 打开*/
            case "password BOX2_UnLock":
                this.guizi3.Interactive();
                break;
            /** 解锁柜子门 打开*/
            case "password BOX3_UnLock":
                this.guizi4.Interactive();
                break;
            /** 密码机器解锁了 开机器下面的门*/
            case "Password machine":
                this.machineGate.Interactive();
                break;
            /** 显示出了画的四角*/
            case "hua2_touming_Blood_Amount":
                this.isShowDrawCorner = true;
                break;
            /** 点击了画的一角*/
            case "corner1":
                if (this.isShowDrawCorner && !this.isCornner1Zuan && this.IsSelectProp(GamePropConst.Electric_drill))
                {
                    this.ShowDialog(DialogDataConst.remove_screw);
                    /** 画钻孔*/
                    this.isCornner1Zuan = true;
                    this.CheckRotateDraw();
                    /** 播放电钻音*/
                    window.gameFacade.SoundMng.playSound(Sound.soundClipArr.DIAN_ZUAN);
                }
                break;
            /** 点击了画的一角*/
            case "corner2":
                if (this.isShowDrawCorner && !this.isCornner2Zuan && this.IsSelectProp(GamePropConst.Electric_drill))
                {
                    this.ShowDialog(DialogDataConst.remove_screw);
                    /** 画钻孔*/
                    this.isCornner2Zuan = true;
                    this.CheckRotateDraw();
                    /** 播放电钻音*/
                    window.gameFacade.SoundMng.playSound(Sound.soundClipArr.DIAN_ZUAN);
                }
                break;
            /** 点击了画的一角*/
            case "corner3":
                if (this.isShowDrawCorner && !this.isCornner3Zuan && this.IsSelectProp(GamePropConst.Electric_drill))
                {
                    this.ShowDialog(DialogDataConst.remove_screw);
                    /** 画钻孔*/
                    this.isCornner3Zuan = true;
                    this.CheckRotateDraw();
                    /** 播放电钻音*/
                    window.gameFacade.SoundMng.playSound(Sound.soundClipArr.DIAN_ZUAN);
                }
                break;
            /** 点击了画的一角*/
            case "corner4":
                if (this.isShowDrawCorner && !this.isCornner4Zuan && this.IsSelectProp(GamePropConst.Electric_drill))
                {
                    this.ShowDialog(DialogDataConst.remove_screw);
                    /** 画钻孔*/
                    this.isCornner4Zuan = true;
                    this.CheckRotateDraw();
                    /** 播放电钻音*/
                    window.gameFacade.SoundMng.playSound(Sound.soundClipArr.DIAN_ZUAN);
                }
                break;
            /** 移动方块成功 开启电梯*/
            case "MoveCubeLock_MoveCubeUnlock":
                this.isOpenDianTi = true;
                this.diantiGate2.Interactive();
                this.diantiGate1.Interactive();
                this.cameraControl.PopMoveStack();
                break;
            /** 点击最终电梯的门 判断过关*/
            case "endGate":
                if(this.isOpenDianTi)
                {
                    this.FinishLevel();
                }
                break;
            default:
                break;
        }
        return true;
    }
    /** 检测翻转画*/
    private CheckRotateDraw()
    {
        if (this.isCornner1Zuan && this.isCornner2Zuan && this.isCornner3Zuan && this.isCornner4Zuan)
        {
            this.cameraControl.PopMoveStack();
            this.drawObj.Interactive();
        }
    }
    private ShowDialogNothing()
    {
        this.ShowDialog(DialogDataConst.nothing_here);
    }
}